<!DOCTYPE html>
<html>
<head lang="zh-cmn-Hans">
    <meta charset="UTF-8">
    <title>产品集列表</title>
    <link rel="stylesheet" type="text/css" href="../css/default.css">
    <link rel="stylesheet" type="text/css" href="../js/jquery-easyui-1.3.5/themes/gray/easyui.css">
    <link rel="stylesheet" type="text/css" href="../js/jquery-easyui-1.3.5/themes/icon.css"/>
    <script type="text/javascript" src="../js/jquery-easyui-1.3.5/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="../js/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../js/extends.js"></script>
    <script type="text/javascript" src="../js/common.js"></script>
    <script>

        function delete_product_set(row) {
            $.ajax({
                type: "POST",
                url: "/rest/admin/productsets/" + row.id,
                success: function () {
                    $('#table_product_set').datagrid('clearSelections');
                    $('#table_product_set').datagrid('reload');
                },
                error: function (response) {
                    $.messager.alert('错误', '删除' + row.name + '失败：' + response.responseText, 'error');
                }
            });
        }

        function nedit_product_set() {
            var data = $("form").serializeObject();
            data["id"] = parseInt($("#id").val());

            $.ajax({
                type: "POST",
                url: "/rest/admin/productsets",
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(data),
                success: function (result) {
                    //$("#child")[0].contentWindow.reload();
                    //$("#parent_win").window("close");
                    $('#table_product_set').datagrid('clearSelections');
                    $('#table_product_set').datagrid('reload');
                    $("#child_win").window("close");
                }
            });
        }

        function init_nedit_data() {
            var row = $('#table_product_set').datagrid('getSelected');
            $("#id").val(row.id);
            $("#name").val(row.name);
            $("#manager").val(row.manager);
        }

        //        function reload() {
        //            $('#table_product_set').datagrid('reload');
        //        }

        $(function () {
            $.ajaxSetup({cache: false});
            $("#table_product_set").datagrid({
                height: $("#body").height() - $('#search_area').height() - 5,
                width: $("#body").width(),
                idField: 'id',
//                data: [{"id":1,"name":"1","manager":"2"}],
                //url:"datagrid.json",
                url: "/rest/admin/productsets",
                method: "get",
                singleSelect: true,
                nowrap: true,
                fitColumns: true,
                rownumbers: true,
                showPageList: false,
                columns: [[
                    {field: 'name', title: '产品集名称', width: 100, halign: "center", align: "left"},
                    {field: 'manager', title: '负责人', width: 100, halign: "center", align: "left"}
                ]],
                toolbar: '#tt_btn',
                pagination: false,
                onDblClickRow: function (rowIndex, rowData) {
                    viewDetail(rowData.userId);
                }
            });

            //新增弹出框
            $("#save").on("click", function () {
                // $parent("#parent_win").window({
//                $parent("#parent_win").window({
//                    width: 10,
//                    height: 10,
//                    href: '/admin/nedit_product_set.html',
//                    title: '新增产品集p'
//                });
                $('#table_product_set').datagrid('clearSelections');
                $("#child_win").window({
                    width: 300,
                    height: 200,
                    href: '/admin/nedit_product_set.html',
                    title: '新增产品集'
                });
            });
            //修改
            $("#update").on("click", function () {
                var row = $('#table_product_set').datagrid('getSelected');
                $("#child_win").window({
                    width: 300,
                    height: 200,
                    href: '/admin/nedit_product_set.html',
                    title: '修改产品集'
                });
            });
            //删除
            $("#delete").on("click", function () {
                var row = $('#table_product_set').datagrid('getSelected');
                $parent.messager.confirm('提示', '确认删除' + row.name + '?', function (r) {
                    if (r) {
                        delete_product_set(row);
                    }
                });
            });
        })

        function viewDetail(date, id) {
            $parent.messager.alert("提示", "查询详细", "info");
        }

        //监听窗口大小变化
        window.onresize = function () {
            setTimeout(domresize, 300);
        };
        //改变表格宽高
        function domresize() {
            $('#table_product_set').datagrid('resize', {
                height: $("#body").height() - $('#search_area').height() - 5,
                width: $("#body").width()
            });
        }
    </script>
</head>
<body class="easyui-layout">
<div id="body" region="center">
    <!-- 查询条件区域 -->
    <div id="search_area">
        <div id="conditon">
            <table border="0">
                <tr>
                    <td>用户名：</td>
                    <td><input name="userName" id="userName"/></td>
                    <td>&nbsp;性别：</td>
                    <td><input name="sex" id="sex"/></td>
                    <td>&nbsp;部门：</td>
                    <td><input name="department" id="department"/></td>
                    <td>
                        <a href="javascript:void(0)" class="easyui-linkbutton my-search-button" iconCls="icon-search"
                           plain="true">查询</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton my-search-button" iconCls="icon-reset"
                           plain="true">重置</a>
                    </td>
                </tr>
            </table>
        </div>
        <!--<span id="openOrClose">111</span>-->
    </div>
    <!-- 数据表格区域 -->
    <table id="table_product_set" style="table-layout:fixed;"></table>
    <!-- 表格顶部工具按钮 -->
    <div id="tt_btn">
        <a href="javascript:void(0)" id="save" class="easyui-linkbutton" iconCls="icon-add" plain="true">新增</a>
        <a href="javascript:void(0)" id="update" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
        <a href="javascript:void(0)" id="delete" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
    </div>
</div>

<!-- 用于弹出框 -->
<div id="child_win"></div>

</body>
</html>